package perspectives;

import perspectives.PropertyManager.PropertyWidget;

	public class Property<T> {
		
		private String name;
		private T value;
		private boolean visible;		
		private boolean readOnly;
		private boolean shared;
		
		private PropertyWidget propertyWidget;
		
		public Property(String n) {
			this.name = n;
			
			visible = true;
			readOnly = false;
			shared = false;
			
			propertyWidget = null;
			
		}
		
		public String getName()
		{
			return name;
		}
		
		public String getDisplayName()
		{
			String[] s = name.split("\\.");
			String labelText =  s[s.length-1];
			String ext = "";
			if (labelText.length() > 13)
				ext = "..";
			labelText = labelText.substring(0, Math.min(labelText.length(), 13)) + ext;
			//return s[s.length-1];
			return labelText;
		}
		
		public void setValue(T newValue)
		{
			value = newValue;
			if (propertyWidget != null)
				propertyWidget.setProperty(newValue);
				
		}
		
		public T getValue()
		{
			return value;
		}
		
		public void setVisible(boolean v)
		{
			visible = v;
			if (propertyWidget != null)
				propertyWidget.setPropertyVisible(v);
			
		}
		
		public boolean getVisible()
		{
			return visible;
		}
		
		public void setReadOnly(boolean r)
		{
			readOnly = r;
			if (propertyWidget != null)
				propertyWidget.setPropertyReadOnly(r);
		}
		
		public boolean getReadOnly()
		{
			return readOnly;
		}
		
		public void setPropertyWidget(PropertyWidget pw)
		{
			propertyWidget = pw;
		}
		
		public PropertyWidget getPropertyWidget()
		{
			return propertyWidget;
		}
		
		public void setShared(boolean s)
		{
			shared = s;
		}
		
		public boolean getShared()
		{
			return shared;
		}
	}